const bodyParser = require('body-parser')
var express = require('express')

var app = express()

app.engine('html',require('express-art-template'))

app.use(bodyParser.urlencoded({ extended: false}))
app.use(bodyParser.json())

app.use('/public/', express.static('./public/'))
app.use('/views/', express.static('./views/'))

var comments = [{
    name: '张三',
    message: '今天天气不错',
    dateTime: '2021-01-13'
},
{
    name: '张三2',
    message: '今天天气不错',
    dateTime: '2021-01-13'
},
{
    name: '张三3',
    message: '今天天气不错',
    dateTime: '2021-01-13'
},
{
    name: '张三4',
    message: '今天天气不错',
    dateTime: '2021-01-13'
},
{
    name: '张三5',
    message: '今天天气不错',
    dateTime: '2021-01-13'
},
]

app.get('/',function (req, res) {
    res.render('index.html', { comments: comments})
})

app.get('/post', function (req, res) {
    res.render('post.html')
})

app.post('/post', function (req, res){
    var comment = req.body
    comment.dateTime = '2021-01-15'
    comments.unshift(comment)
    res.redirect('/')
})

// app.get('/pinglun', function(req, res){
//     var comment = req.query
//     comment.dateTime = '2021-01-15'
//     comments.unshift(comment)
//     res.redirect('/')
// })

app.listen(3000, function () {
    console.log('running......')
})